package com.ag.admin.service.impl;



import javax.servlet.ServletContext;

import org.apache.struts2.ServletActionContext;
import org.codehaus.xfire.XFireFactory;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;
import org.springframework.stereotype.Service;
import com.ag.admin.webservice;
import com.ag.admin.service.ICheckUserService;
import com.opensymphony.xwork2.ActionContext;

/**
 * 
 * @author 邓国明 
 * 用来向远程webService验证用户是否正确
 * 
 */
@Service("CheckUserServiceImpl")
public class CheckUserServiceImpl implements ICheckUserService {

	@Override
	public boolean checkUser(String name, String password) {
		//return true;
		if(name.equals("jpagg")&&password.equals("jpagg123456")){
			return true;
		}else{
		ActionContext ac = ActionContext.getContext();
		ServletContext sc = (ServletContext) ac
				.get(ServletActionContext.SERVLET_CONTEXT);
		String basePath = sc.getRealPath("/");
		String cacertsPath=(basePath+"dgm/casstore").replace("\\", "/");
		System.out.println(cacertsPath+"***********");
		System.setProperty("javax.net.ssl.trustStore",cacertsPath);
		
		org.codehaus.xfire.service.Service srvcModel =  new ObjectServiceFactory().create(webservice.class);
		XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
				.newInstance().getXFire());

		String helloWorldURL = "https://cas.gzfda.gov.cn/cas/services/UserService";
		webservice srvc = null; // 接口
		try {
			srvc = (webservice) factory.create(srvcModel, helloWorldURL); // 得到东西
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		System.out.println(srvc.login(name, password));
		return srvc.login(name, password);
		
		}
	}

}
